<?php

namespace app\admin\command;

use app\admin\model\Reserve;
use app\admin\model\Room;
use app\common\library\Yunding;
use Carbon\Carbon;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Db;
use think\Exception;
use think\Log;

class ReleaseRoom extends Command
{

    protected function configure()
    {
        $this->setName('release_room')
            ->setDescription('release room');
    }

    protected function execute(Input $input, Output $output)
    {
        @ini_set("memory_limit", '-1');
        $stime = microtime(true);

        $reserves = Reserve::where('starttime', '>=', Carbon::now()->startOfDay()->toDateTimeString())
            ->where('re_status', 0)
            ->select();
        foreach ($reserves as $reserve) {
            if (time() >  240 + $reserve->createtime) {
                $reserve->delete();
            }
        }

        $etime = microtime(true);//获取程序执行结束的时间
        $total = $etime - $stime;   //计算差值
        $output->writeln($total);
    }

}
